package com.xyh.system.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xyh.system.model.Dept;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author xyh
 * @since 2020-12-30
 */
@Repository
public interface DeptMapper extends BaseMapper<Dept> {
    /**
     * 获取所有部门树
     *
     * @return
     */
    List<Dept> selectAllDeptTree();

    /*
     * 通过parentId查询父级菜单下的所以子集菜单
     */
    @Select("SELECT dept_id, parent_id, dept_name, order_num, create_time, modify_time " +
            "FROM dept WHERE parent_id = #{parentId} ORDER BY order_num")
    List<Dept> selectChildDeptByParentId(Integer parentId);

    @Select("SELECT IFNULL(MAX(order_num),0) FROM dept")
    Integer selectMaxOrderNum();
}
